//
//  VideoEditorViewController.swift
//  GifUsage
//
//  Created by han on 2020/12/31.
//  Copyright © 2020 Ting Han. All rights reserved.
//

import UIKit
import Photos
import AVFoundation

class VideoEditorViewController: UIViewController {
    
    @IBOutlet weak var containerView: UIView!
    @IBOutlet weak var slider: UISlider!
    
    @IBOutlet weak var totalLabel: UILabel!
    @IBOutlet weak var currentLabel: UILabel!
    
    var asset: PHAsset?
    
    var urlAsset: AVURLAsset?
    
    var timeScale: CMTimeScale = 10
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    
    @IBAction func sliderValueChanged(_ sender: Any) {
    }
    
    @IBAction func playAction(_ sender: Any) {
   
    }
    
    @IBAction func muteAction(_ sender: Any) {
   
    }
    
    @IBAction func takeScreenShot(_ sender: Any) {
        
        
    }
}

extension VideoEditorViewController {
    func loadVideoData() {
        guard let asset = asset else { return }
        let options = PHVideoRequestOptions()
        options.isNetworkAccessAllowed = true
        options.version = .original
        
        PHImageManager.default().requestAVAsset(forVideo: asset, options: options) { (avAsset, audioMix, info) in
            if avAsset?.isKind(of: AVURLAsset.self) == true {
                self.urlAsset = avAsset as? AVURLAsset
            }
        }
    }
    
    func totalDuration() -> TimeInterval {
        guard let urlAsset = urlAsset else { return 0 }
        
        let duration = urlAsset.duration
        return CMTimeGetSeconds(duration)
    }
    
   
}
